﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class FeeBLL
    {
        private static int feeID = 0;
        GaraDataContext DB = new GaraDataContext();
        public IQueryable SelectALL()
        {
            return (from p in DB.Fees select p).AsQueryable();
        }

        public string Insert(FeeDTO feeDTO)
        {
            try
            {
                Fee fee = new Fee();
                fee.FeeID = feeID++;
                fee.FeeName = feeDTO.FeeName;
                fee.Price = feeDTO.Price;

                DB.Fees.InsertOnSubmit(fee);
                DB.SubmitChanges();
                return MessageAction.Success;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

        public string Update(FeeDTO feeDTO)
        {
            try
            {
                Fee fee = DB.Fees.Where(s => s.FeeID == feeDTO.FeeID).FirstOrDefault();
                fee.FeeName = feeDTO.FeeName;
                fee.Price = feeDTO.Price;

                DB.SubmitChanges();
                return MessageAction.Success;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
}
